#include "CheckboxSetting.h"

CheckboxSetting::CheckboxSetting(checkBox* tex, QWidget *parent)
	: QDialog(parent),tex(tex)
{
	ui.setupUi(this);
	ui.sxSpinBox->setValue(tex->scale.x());
	ui.sySpinBox->setValue(tex->scale.y());
	ui.szSpinBox->setValue(tex->scale.z());
	ui.checkBox->setChecked(tex->contrast);
	ui.comboBox->setCurrentIndex(tex->dir);

	connect(this, SIGNAL(accepted()), this, SLOT(onApply()));
	connect(ui.colorBtn_1, SIGNAL(clicked()), this, SLOT(onChangeColor_1()));
	connect(ui.colorBtn_2, SIGNAL(clicked()), this, SLOT(onChangeColor_2()));
	
}

void CheckboxSetting::paintEvent(QPaintEvent* e)
{
	QPainter p(this);
	p.setBrush(vec2color(tex->color));
	p.drawRect(90, 20, 21, 21);
	p.setBrush(vec2color(tex->darkColor));
	p.drawRect(200, 20, 21, 21);
}

CheckboxSetting::~CheckboxSetting()
{
}

void CheckboxSetting::onApply()
{
	tex->scale.setX(ui.sxSpinBox->value());
	tex->scale.setY(ui.sySpinBox->value());
	tex->scale.setZ(ui.szSpinBox->value());
	tex->contrast = ui.checkBox->isChecked();
	tex->dir = ui.comboBox->currentIndex();
}

void CheckboxSetting::onChangeColor_1()
{
	QColorDialog cd;
	QColor color = cd.getColor();
	tex->color = color2vec(color);
	repaint();
}

void CheckboxSetting::onChangeColor_2()
{
	QColorDialog cd;
	QColor color = cd.getColor();
	tex->darkColor = color2vec(color);
	repaint();
}